import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/config/app_config.dart';
import 'package:flutter_douban/config/sqflite/user_db_provider.dart';
import 'package:flutter_douban/main_page/me/page/user_config_page.dart';
import 'package:shared_preferences/shared_preferences.dart';

class HasLoginView extends StatefulWidget {
  final String numberId;
  const HasLoginView({Key? key, required this.numberId}) : super(key: key);

  @override
  _HasLoginViewState createState() => _HasLoginViewState();
}

class _HasLoginViewState extends State<HasLoginView> {
  late Map _map;
  String _numberId = '';
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // _getData();
  }

  Future<void> _getData() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String? numberId = prefs.getString(AppConfig.numberId);
    if(numberId == null){
      numberId = '123';
    }
    UserDbProvider provider = new UserDbProvider();
    late Map map;
    provider.getUserData(numberId).then((value) => {
          map = value,
          setState(() {
            _map = map;
            _numberId = numberId!;
          }),
        });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        color: Colors.white,
        width: MediaQuery.of(context).size.width,
        child: Stack(
          children: [
            Container(
              color: AppColors.yellow,
              height: 200,
              width: MediaQuery.of(context).size.width,
            ),
            Positioned(
                top: 20,
                width: MediaQuery.of(context).size.width,
                height: 200,
                child: Container(
                  padding: EdgeInsets.only(left: 60, top: 5),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: new Border.all(color: AppColors.yellow, width: 1),
                    borderRadius: BorderRadius.circular(14),
                  ),
                  child: Row(
                    children: [
                      Expanded(
                        child: Column(
                          children: [
                            Text(
                              '关注',
                              style: TextStyle(
                                  fontSize: 10, color: AppColors.qianTextColor),
                            ),
                            Text('0',
                                style: TextStyle(
                                    fontSize: 13, color: AppColors.black)),
                          ],
                        ),
                      ),
                      Expanded(
                        child: Column(
                          children: [
                            Text(
                              '粉丝',
                              style: TextStyle(
                                  fontSize: 10, color: AppColors.qianTextColor),
                            ),
                            Text('0',
                                style: TextStyle(
                                    fontSize: 13, color: AppColors.black)),
                          ],
                        ),
                      ),
                      Expanded(
                        child: Column(
                          children: [
                            Text(
                              '被收藏',
                              style: TextStyle(
                                  fontSize: 10, color: AppColors.qianTextColor),
                            ),
                            Text('0',
                                style: TextStyle(
                                    fontSize: 13, color: AppColors.black)),
                          ],
                        ),
                      ),
                      Expanded(
                        child: Column(
                          children: [
                            Text(
                              '被学做',
                              style: TextStyle(
                                  fontSize: 10, color: AppColors.qianTextColor),
                            ),
                            Text('0',
                                style: TextStyle(
                                    fontSize: 13, color: AppColors.black)),
                          ],
                        ),
                      ),
                    ],
                  ),
                )),
            Positioned(
                top: 0,
                left: 15,
                child: InkWell(
                  onTap: () {
                    Navigator.of(context)
                        .push(MaterialPageRoute(builder: (_) {
                      return UserConfigPage();
                    }));
                  },
                  child: Image.asset(
                    'assets/images/common/note_logo@2x.png',
                    width: 50,
                    height: 50,
                  ),
                )),
            Positioned(
                top: 70,
                left: 15,
                child: Container(
                  width: MediaQuery.of(context).size.width - 30,
                  height: 100,
                  color: Colors.white,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '用户已登录',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 14,
                            color: Colors.black),
                      ),
                      Text(
                        '用户Id: ${widget.numberId}',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 14,
                            color: Colors.black),
                      ),
                      Text(
                        '个人简介: 这个人很懒什么也没留下',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 14,
                            color: Colors.black),
                      )
                    ],
                  ),
                )),
          ],
        ));
  }
}
